package org.c41.util;

public class SynResource<T>{

	private Loader<T> myloader;
	private SynRunner runner;
	private T resource;
	
	public SynResource(Loader<T> loader){
		this.myloader=loader;
		runner=new SynRunner(new Runnable() {
			
			@Override
			public void run() {
				resource = myloader.load();
			}
		});
	}
	
	public void load(){
		this.runner.start();
	}
	
	public T get(){
		this.runner.waitFor();
		return this.resource;
	}
	
	public static interface Loader<T>{
		
		public T load();
		
	}
	
}
